package com.matt.sooncleaner.wifiscan

import android.content.Context
import android.content.Intent
import android.provider.Settings.ACTION_WIFI_SETTINGS
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.TimeUtils

const val BAND_5_GHZ_START_FREQ_MHZ = 5160

/**
 * 5 GHz band frequency of last channel in MHz
 * @hide
 */
const val BAND_5_GHZ_END_FREQ_MHZ = 5885

private const val KEY_LAST_SCAN_TIME = "lastWifiScanTime"

fun is5GHz(freqMhz: Int): Boolean {
    return freqMhz in BAND_5_GHZ_START_FREQ_MHZ..BAND_5_GHZ_END_FREQ_MHZ
}

fun startWifiSettings(context: Context) {
    context.startActivity(Intent(ACTION_WIFI_SETTINGS))
}

fun saveWifiScanTime() {
    val timeStr = TimeUtils.getSafeDateFormat("MM-dd HH:mm").format(System.currentTimeMillis())
    SPUtils.getInstance().put(KEY_LAST_SCAN_TIME, timeStr)
}

fun getLastWifiScanTime(): String = SPUtils.getInstance().getString(KEY_LAST_SCAN_TIME, "-")
